<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * 订单查询ajax类
 * @package  ajax
 * @subpackage  backend
 * @author   allen.qiang
 */

quanli_require('module/base/bill/billSearch.class.php');

quanli_require('module/base/company/companyMaster.class.php');

//部门类
quanli_require('module/base/system/sysDepartment.class.php');


class ajax_billSearch {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch($_REQUEST['operFlg']) {

                case 1: //订单订单查询
                    $this->searchBill();
                    break;

                case 2: //查询订单详情
                    $this->searchBillDetail();
                    break;
                //add by allen.qiang  <allen.qiang@fistforward.com> 2015-01-21 allen.qiang FUN-AC-0028-下午茶项目 start
                case 3: //下午茶订单查询页面
                    $this->XWC_searchBill();
                    break;
                //add by allen.qiang  <allen.qiang@fistforward.com> 2015-01-21 allen.qiang FUN-AC-0028-下午茶项目 end

                case 100: //开票
                    $this->makeTicket();
                    break;

                case 9: //查询试吃订单
                    $this->searchBill9();
                    break;

                default:
                    backendError();
                    break;

            }

        } else {
            backendError();

        }

    }

    /**
     * 订单查询
     * @author create by allen.qiang
     */
    private function searchBill() {

        global $G_PGLOB;
        //实例查询类
        $billSearch = new billSearch();

        $bill_info_array = $billSearch->searchBillInfo( $_REQUEST );

        //组织返回的数据
        $result_array = array(
            'page' => $_REQUEST['page'],
            'total' => $_REQUEST['count'],
            'rows' => array()
        );

        if ($bill_info_array) {
            foreach($bill_info_array as &$bill) {
                $is_al = 0;
                //区分是否是澳粒的订单
                if($bill['billPlatform'] == 2){
                    $is_al = 1;
                }

                $operate = '';

                //正常订单
                if($G_PGLOB->has_permission(1001) || $G_PGLOB->has_permission(1025)){

                    //审核
                    if($G_PGLOB->has_permission(1012) && $is_al == 0){
                        if ( $bill['bill_status'] == 0 && ($bill['pay_type'] == 1 || $bill['pay_status'] == 1 || ($bill['pay_type'] == 2 && $bill['bill_online_money'] > 0))&& $bill['billType']!= 9) {
//                        if ( $bill['bill_status'] == 0 && ($bill['pay_type'] == 1 || $bill['pay_status'] == 1) && $bill['billType']!= 9) {
                            $remark = urlencode($bill['remark']);
                            $operate .= '<a href="javascript: void(0);" onclick="bill.audit(\'' . $bill['bill_no'] . '\',\''.$remark.'\');">审核</a>&nbsp;&nbsp;';
                        }
                    }

                    //修改
                    //mod by 20141111 sunqiang FUN-BK-0021 订单为已下车状态可修改订单 start

                    if
                    ( $bill['billType'] != 9 &&
                        (
                            ($G_PGLOB->has_permission(1010) && in_array($bill['bill_status'], array(0, 1)) ) ||
                            ($G_PGLOB->has_permission(1029) && in_array($bill['bill_status'], array(5, 6)) )
                        )

                    )
                    {
                        if($is_al){
                            $operate .= '<a href="javascript: bill.AL_alter(\'' . $bill['bill_no'] . '\')">修改</a>&nbsp;&nbsp;';
                        }else{
                            $operate .= '<a href="javascript: bill.alter(\'' . $bill['bill_no'] . '\')">修改</a>&nbsp;&nbsp;';
                        }

                    }

                    //取消
                    if($G_PGLOB->has_permission(1011)){
                        if ( in_array($bill['bill_status'], array(0, 1, 2, 3))&&$bill['billType']!=9) {
                            $operate .= '<a href="javascript: void(0);" onclick="bill.cancel(\'' . $bill['bill_no'] . '\');">取消</a>&nbsp;&nbsp;';
                        }
                    }

                    //退货
                    if($G_PGLOB->has_permission(1013) && $bill['billType']!=9){
                        if(in_array($bill['bill_status'], array(4, 5, 6, 7)) && ( ($bill['bill_withdrawAmount'] + $bill['bill_rejectionAmount']) < $bill['bill_totalAmount'] )){
                            $operate .= '<a href="javascript: void(0);" onclick="bill.returnGoods(\'' . $bill['bill_no'] . '\');">退货</a>&nbsp;&nbsp;';
                        }
                    }

                    //开票
                    if($G_PGLOB->has_permission(1003) && $bill['billType']!=9 ){ //开票
                        if($bill['invoice'] == 1 && $bill['is_the_invoice'] == 0 && $bill['bill_status'] != 10){
                            $operate .= '<a href="javascript: void(0);" onclick="bill.makeTicket(\'' . $bill['bill_no'] . '\');">开票</a>&nbsp;&nbsp;';
                        }
                    }

                    //下车/只有澳粒订单有此功能
                    if( $is_al == 1 && $bill['bill_status'] == 1){
                        $operate .= '<a href="javascript: void(0);" onclick="bill.debus(\'' . $bill['bill_no'] . '\');">下车</a>&nbsp;&nbsp;';
                    }


                    if(in_array($bill['bill_status'], array(5,6)) && $bill['billType'] != 9 ){

                        //验证现金卡
                        if($G_PGLOB->has_permission(1021) && $is_al == 0){
                            if($bill['bill_receivable_money'] - $bill['deliver_feePaid'] > 0){
                                $operate .= '<a href="javascript: void(0);" onclick="bill.showUseCardDialog(\'' . $bill['bill_no'] . '\',\''.$bill['bill_code'].'\',\''.$bill['bill_receivable_money'].'\');">验证现金卡</a>&nbsp;&nbsp;';
                            }
                        }

                        //改运费
                        if( $G_PGLOB->has_permission(1024) && !in_array($bill['billType'], array(2, 3, 5, 7)) ){
                            $operate .= '<a href="javascript: void(0);" onclick="bill.showFeePaidDialog(\'' . $bill['bill_no'] . '\',\''.$bill['bill_code'].'\',\''.$bill['deliver_feePaid'].'\');">修改运费</a>&nbsp;&nbsp;';
                        }

                    }
                }

                //判断配送时间是否为0
                $res = explode( ':',$bill['send_end_time']);
                $send_end_time_num = 0;
                foreach( $res as $val ){
                    if( intval($val) > 0 ){
                        $send_end_time_num = 1;
                    }
                }

                //到货时间
                if( $send_end_time_num  ){
                    $arrive_time = $bill['send_date'].' '.$bill['send_start_time'] .'～'.$bill['send_end_time'];
                }else{
                    $arrive_time = $bill['send_date'].' '.$bill['send_start_time'];
                }

                if( $bill['special_status'] == 1){ //无密码登录
                    $color = 'blue';
                }else if( $bill['special_status'] == 2){ //超出配送站运能上限
                    $color = 'red';
                }else if( $bill['special_status'] == 3){ //异地付款
                    $color = '#00CC33';
                }else{
                    $color ='';
                }

                if ($bill['bill_other_address_pay'] == 0 || strstr($bill['distribution_name'],"未分配") ) {
                    $bill['bill_code'] .= ' 【收货地址精度不准确】';
                }


                $bill_warning = '';
                if($bill['bill_status'] == 0 && $bill['pay_status'] > 0 && $G_PGLOB->sys_date > $bill['send_date'])
                {
                    $bill_warning = '<span style="color: red;font-size: 14px;font-weight: bold;" title="已付款,但已过配送日期">  ! </span>';
                }

                //取得发票信息
                $invoiceInfo =  $this->getInvoiceInfo($bill);

                $result_array['rows'][] = array(
                    'id' => $bill['bill_no'],
                    'font_color'=>$color,
                    'cell' => array(
                        $operate,
                        '<a href="/quanliadmin/app/bill/billSearch.pscript?operFlg=9&bill_no=' . $bill['bill_no'] . '" target="_blank">' . $bill['bill_code'] . '</a>'.$bill_warning,
                        $bill['billTypeName'],
                        $bill['bill_status_name'],
                        $GLOBALS['urgent'][$bill['is_urgent']],
                        $bill['payTypeName'],
                        $bill['paying_agent_str'],
                        $arrive_time,
                        $bill['createTime'],
                        $bill['goods_name_str'],
                        $bill['bill_totalAmount'],
                        $bill['tableware_amount'],
                        $bill['candle_amount'],
                        $bill['bill_money'],                                                    //订单金额
                        $bill['bill_receivable_money'],                                       //应收金额
                        //$bill['bill_unreceived_money'],                                         //去零金额  (前端暂无显示)
                        $bill['bill_received_money'],                                         //已收金额
                        $bill['auth_alter'] == 1 ? "是" : "否",                                //是否调价
                        $bill['return_price'],                                                 //退货金额
                        $bill['purchase_price'],                                               //配送自购金额
                        $bill['deliver_feePaid'],                                              //实际运费
                        $bill['deliver_city'],
                        $bill['deliver_county'],
                        $bill['distribution_name'],
                        $bill['distribution_technicia'],
                        $this->getDistribution_technician_mobile($bill['distribution_technician_id']),  //配送员手机号
                        $bill['deliver_mobile'],
                        $bill['deliver_name'],
                        $bill['creator'],
                        $bill['bill_withdraw_name'],
                        $invoiceInfo['invoice_type'],                                           //发票类型
                        $invoiceInfo['invoice_title_type'],                                    //抬头类型
                        $invoiceInfo['invoice_title'],                                          //发票抬头
                        $invoiceInfo['invoice_amount'],                                         //发票金额
                        $invoiceInfo['invoice_content'],                                        //发票内容
                        $invoiceInfo['invoice_number']                                          //发票号
                    )
                );
            }
        }
        echo json_encode($result_array);
    }

    /**
     * @param $bill
     * 取得发票信息
     */
    private function getInvoiceInfo($bill){
        $invice =  array(
            'invoice_type' => '',                                                   //发票类型
            'invoice_type' => '',                                                   //抬头类型
            'invoice_title' => '',                                                  //发票抬头
            'invoice_amount' => '',                                                 //发票金额
            'invoice_content' => '',                                                //发票内容
            'invoice_number' => '',                                                 //发票号
        );

        //发票类型
        if( $bill['invoice_type'] == 1){
            $invice['invoice_type'] = '商业零售发票';
        }
        //抬头类型
        if( $bill['invoice_title_type'] == 1){
            $invice['invoice_title_type']  = '个人';
        }else if( $bill['invoice_title_type'] == 2){
            $invice['invoice_title_type'] = '单位';
        }
        //有发票
        if( $bill['invoice'] == 1 ) {
            $invice['invoice_title'] = $bill['invoice_title'];
            $invice['invoice_amount'] = $bill['invoice_amount'];
            $invice['invoice_content'] = $bill['invoice_content'];
            $invice['invoice_number'] = $bill['invoice_number'];
        }
        return $invice;
    }

    /*
     * 查询试吃订单 add by sunqiang 20140907
     * */
    private function searchBill9(){

        global $G_PGLOB;

        //获得用户的所属部门及以下部门
        $PS_LOGIN_SESSION =$G_PGLOB->sessionCache_get('PS_LOGIN_SESSION');
        $departmentID = $PS_LOGIN_SESSION['department'];//当前部门id

        //实例化部门类
        $sysDepartment = new sysDepartment();

        //部门数据
        $department_array = array();
        //递归查询部门数据
        $sysDepartment->searchDepartment( $department_array,0,-1,$departmentID);

        //递归获得多维数组索引的方法（部门id）的方法
        function getKey( $array , &$foreachKey_array){

            if( is_array( $array )){
                foreach( $array as $k=>$v){
                    if( $k == "departmentID"){
                        $foreachKey_array[] = $v;
                    }

                    if( is_array( $v )){
                        getKey( $v, $foreachKey_array );
                    }
                }
            }
        }

        $departmentKeyArray = array();
        getKey( $department_array, $departmentKeyArray );

        if( !empty($departmentKeyArray) ) { //当前登录用户权限下部门
            $str_departmentID = implode( ',',$departmentKeyArray );
            $_REQUEST['extend'] = " AND departmentID IN (".$str_departmentID.")";
        } else { //当前登录用户没有任何所属部门
            //组织返回的数据
            $result_array = array(
                'page' => 1,
                'total' => 0,
                'rows' => array()
            );
            echo json_encode($result_array);
        }

        //实例化大客户信息类
        $companyMaster = new companyMaster();
        if( isset( $_REQUEST['search_departmentID'] )){
            // $_REQUEST['departmentID'] = $_REQUEST['search_departmentID'];

            if($_REQUEST['search_departmentID']!=""){

                $department_arrays = array();
                //实例化部门类
                $sysDepartments = new sysDepartment();
                //递归查询部门数据
                $sysDepartments->searchDepartment( $department_arrays,0,-1,$_REQUEST['search_departmentID']);
                $departmentKeyArrays= array();
                getKey( $department_arrays, $departmentKeyArrays );
                $str_departmentIDs = implode( ',',$departmentKeyArrays );

                $_REQUEST['departmentID'] =$str_departmentIDs;

            }else{
                $_REQUEST['departmentID'] = $_REQUEST['search_departmentID'];
            }

        }

        //实例查询类
        $billSearch = new billSearch( $G_PGLOB->DBCA );
        $bill_info_array = $billSearch->searchBillInfo9( $_REQUEST );

        //组织返回的数据
        $result_array = array(
            'page' => $_REQUEST['page'],
            'total' => $_REQUEST['count'],
            'rows' => array()
        );

        if ($bill_info_array) {

            foreach($bill_info_array as &$bill) {

                $operate = '';
                if( $G_PGLOB->has_permission(60002) ){//试吃订单

                    //审核
                    if($G_PGLOB->has_permission(1012)){
                        if ( $bill['bill_status'] == 0 && ($bill['pay_type'] == 1 || $bill['pay_status'] == 1)&&$bill['billType']==9  ) {
                            $operate .= '<a href="javascript: void(0);" onclick="bill.audit(\'' . $bill['bill_no'] . '\');">审核</a>&nbsp;&nbsp;';
                        }
                    }

                    //修改（未审核）
                    if($G_PGLOB->has_permission(1010)){
                        if ( $bill['bill_status']==0 && $bill['billType']==9 ) {
                            $operate .= '<a href="javascript: bill.alter(\'' . $bill['bill_no'] . '\')">修改</a>&nbsp;&nbsp;';
                        }
                    }
                    //修改（试吃订单已审核后修改权限）
                    if($G_PGLOB->has_permission(60004)){
                        if ( $bill['bill_status']== 1 && $bill['billType']==9) {
                            $operate .= '<a href="javascript: bill.alter(\'' . $bill['bill_no'] . '\')">修改</a>&nbsp;&nbsp;';
                        }
                    }

                    //驳回
                    if($G_PGLOB->has_permission(1011)){
                        if ( in_array($bill['bill_status'], array(0, 1, 2, 3, 4)) && $bill['billType']==9 ){

                            $operate .= '<a href="javascript: void(0);" onclick="bill.display(\'' . $bill['bill_no'] . '\',\''.$bill['bill_status'].'\');">驳回</a>&nbsp;&nbsp;';
                            //增加驳回可修改按钮 add by loreta.cheng 2015-06-12 start
                            //if($bill['billType']==9){
                            //$operate .= '<a href="javascript: void(0);" onclick="bill.display(\'' . $bill['bill_no'] . '\',\'rejectEdit\');">驳回可修改</a>&nbsp;&nbsp;';
                            //}
                            //增加驳回可修改按钮 add by loreta.cheng 2015-06-12 end
                        }
                    }



                    //退货
                    if($G_PGLOB->has_permission(60005)){
                        if(in_array($bill['bill_status'], array(4, 5, 6, 7)) && ( ($bill['bill_withdrawAmount'] + $bill['bill_rejectionAmount']) < $bill['bill_totalAmount'] )){
                            error_log(print_r($operate,1));
                            $operate .= '<a href="javascript: void(0);" onclick="bill.returnGoods(\'' . $bill['bill_no'] . '\');">退货</a>&nbsp;&nbsp;';
                        }
                    }

                }

                //判断配送时间是否为0
                $res = explode( ':',$bill['send_end_time']);

                $send_end_time_num = 0;
                foreach( $res as $val ){
                    if( intval($val) > 0 ){
                        $send_end_time_num = 1;
                    }
                }

                //到货时间
                if( $send_end_time_num  ){
                    $arrive_time = $bill['send_date'].' '.$bill['send_start_time'] .'～'.$bill['send_end_time'];
                }else{
                    $arrive_time = $bill['send_date'].' '.$bill['send_start_time'];
                }

                //发票类型
                if( $bill['invoice_type'] == 1){
                    $invoice_type = '商业零售发票';
                }else{
                    $invoice_type = '';
                }

                //抬头类型
                if( $bill['invoice_title_type'] == 1){
                    $invoice_title_type = '个人';
                }else if( $bill['invoice_title_type'] == 2){
                    $invoice_title_type = '单位';
                }else{
                    $invoice_title_type = '';
                }

                if( $bill['special_status'] == 1){ //无密码登录
                    $color = 'blue';
                }else if( $bill['special_status'] == 2){ //超出配送站运能上限
                    $color = 'red';
                }else if( $bill['special_status'] == 3){ //异地付款
                    $color = '#00CC33';
                }else{
                    $color ='';
                }

                $companysql='select * from company_master where pcustID=?';
                $companyNum = &$G_PGLOB->DBCA->stmt_query($companysql,'s',  $bill['pcustID']);
                $result_array['rows'][] = array(
                    'id' => $bill['bill_no'],
                    'font_color'=>$color,
                    'cell' => array(
                        $operate,
                        '<a href="/quanliadmin/app/bill/billSearch.pscript?operFlg=9&bill_no=' . $bill['bill_no'] . '" target="_blank">' . $bill['bill_code'] . '</a>',

                        $bill['bill_status_name'],


                        $arrive_time,
                        $bill['createTime'],
                        $bill['goods_name_str'],
                        $bill['bill_totalAmount'],

                        $companyNum[0]->company_name,
                        $companyNum[0]->website,
                        $companyNum[0]->connect_name,
                        $companyNum[0]->mobile,


                        $bill['deliver_all_address'],
                        $companyNum[0]->employees_number,
                        $bill['numPeo'],

                        $bill['deliver_mobile'],
                        $bill['deliver_name']

                    )
                );
            }
        }

        echo json_encode($result_array);
    }

    /**
     * add by allen.qiang 20141021 列表增加配送员手机号显示
     * 取得配送员手机
     */
    private function getDistribution_technician_mobile( $distribution_technician_id ){
        global $G_SHOP;
        $temp_item_array = &$G_SHOP->DBCA->stmt_query('SELECT mobile FROM sys_distribution_technician WHERE distribution_technician_id=? ', 'i', $distribution_technician_id);
        if (!$temp_item_array) {
            return '';
        }
        return $temp_item_array[0]->mobile;
    }

    /**
     * 查询订单详情
     */
    private function searchBillDetail() {

        //实例查询类
        $billSearch = new billSearch();

        $bill_info_array = $billSearch->searchBillInfo( $_REQUEST );

        if ($bill_info_array) {
            returnJsonData('ok', 200, $bill_info_array[0]);
        } else {
            returnJsonData('订单信息没有找到', 404);
        }

    }

    /**
     * 开发票
     */
    private function makeTicket(){

        global $G_PGLOB;

        if( !isset($_REQUEST['bill_no']) || empty($_REQUEST['bill_no']) ){
              returnJsonData("参数错误" , 400);
        }

        try{
            //检查订单是否存在
            $bill_obj = new entity('bill_master');
            $bill_obj->bill_no = $_REQUEST['bill_no'] ;
            if (!$G_PGLOB->DBCA->fetch( $bill_obj ))
                throw new Exception( "订单信息没找到，请刷新页面重试" , 404);

            //检查发票是否存在
            if($bill_obj->is_the_invoice == 1){
                throw new Exception( '发票已存在' , 404);
            }

            //更新发票字段
            $bill_obj->invoice_number = $_REQUEST['invoice_number'];
            $bill_obj->is_the_invoice = 1;

            $G_PGLOB->DBCA->save( $bill_obj , 'bill_master' );

            returnJsonData( '保存成功', 200 );

        }catch (Exception $e) {
            if ($e->getCode() > 0)
                returnJsonData( $e->getMessage(), $e->getCode() );
            else {
                error_log($e->getMessage());
                returnJsonData( '系统错误', 500 );
            }
        }

    }

    /**
     * 下午茶订单查询
     * @author allen.qiang  <allen.qiang@fistforward.com> 2015-01-20 allen.qiang FUN-AC-0028-下午茶项目
     */
    private function XWC_searchBill() {

        global $G_PGLOB;

        //实例查询类
        $billSearch = new billSearch();

        if( isset( $_REQUEST['sortname']) &&  $_REQUEST['sortname']=='send_date_time')
        {
            $_REQUEST['sortname'] = 'send_date,send_start_time';
        }

        $bill_info_array = $billSearch->searchBillInfo( $_REQUEST );



        //组织返回的数据
        $result_array = array(
            'page' => $_REQUEST['page'],
            'total' => $_REQUEST['count'],
            'rows' => array()
        );

        if ($bill_info_array) {
            foreach($bill_info_array as &$bill) {

                $operate = '';

                //正常订单
                if($G_PGLOB->has_permission(1030)){

                    //审核
                    if($G_PGLOB->has_permission(1012)){
                        if ( $bill['bill_status'] == 0 && ($bill['pay_type'] == 1 || $bill['pay_status'] == 1 || ($bill['pay_type'] == 2 && $bill['bill_online_money'] > 0))&& $bill['billType']!= 9) {
                            $remark = urlencode($bill['remark']);
                            $operate .= '<a href="javascript: void(0);" onclick="bill.audit(\'' . $bill['bill_no'] . '\',\''.$remark.'\');">审核</a>&nbsp;&nbsp;';
                        }
                    }

                    //打包
                    if($bill['bill_status'] == 2){
                        $operate .= '<a href="javascript: void(0);" onclick="bill.debus(\'' . $bill['bill_no'] . '\');">打包</a>&nbsp;&nbsp;';
                    }

                    //修改
                    if( $bill['billType'] != 9 &&
                        (
                            ($G_PGLOB->has_permission(1010) && in_array($bill['bill_status'], array(0, 1)) )
                        )
                    )
                    {
                         $operate .= '<a href="javascript: bill.alter(\'' . $bill['bill_no'] . '\')">修改</a>&nbsp;&nbsp;';
                    }

                    //取消
                    if($G_PGLOB->has_permission(1011)){
                        if ( in_array($bill['bill_status'], array(0, 1, 2, 3))&&$bill['billType']!=9) {
                            $operate .= '<a href="javascript: void(0);" onclick="bill.cancel(\'' . $bill['bill_no'] . '\');">取消</a>&nbsp;&nbsp;';
                        }
                    }

                    //退货
                    if($G_PGLOB->has_permission(1013) && $bill['billType']!=9){
                        if(in_array($bill['bill_status'], array(4, 5, 6, 7)) && ( ($bill['bill_withdrawAmount'] + $bill['bill_rejectionAmount']) < $bill['bill_totalAmount'] )){
                            $operate .= '<a href="javascript: void(0);" onclick="bill.returnGoods(\'' . $bill['bill_no'] . '\');">退货</a>&nbsp;&nbsp;';
                        }
                    }

                }

                //判断配送时间是否为0
                $res = explode( ':',$bill['send_end_time']);
                $send_end_time_num = 0;
                foreach( $res as $val ){
                    if( intval($val) > 0 ){
                        $send_end_time_num = 1;
                    }
                }

                //到货时间
                if( $send_end_time_num  ){
                    $arrive_time = $bill['send_date'].' '.$bill['send_start_time'] .'～'.$bill['send_end_time'];
                }else{
                    $arrive_time = $bill['send_date'].' '.$bill['send_start_time'];
                }


                if( $bill['special_status'] == 1){ //无密码登录
                    $color = 'blue';
                }else if( $bill['special_status'] == 2){ //超出配送站运能上限
                    $color = 'red';
                }else if( $bill['special_status'] == 3){ //异地付款
                    $color = '#00CC33';
                }else{
                    $color ='';
                }

                if ($bill['bill_other_address_pay'] == 0 || strstr($bill['distribution_name'],"未分配") ) {
                    $bill['bill_code'] .= ' 【收货地址精度不准确】';
                }

                $result_array['rows'][] = array(
                    'id' => $bill['bill_no'],
                    'font_color'=>$color,
                    'cell' => array(
                        $operate,
                        '<a href="/quanliadmin/app/bill/billSearch.pscript?operFlg=9&bill_no=' . $bill['bill_no'] . '" target="_blank">' . $bill['bill_code'] . '</a>',
                        $bill['billTypeName'],
                        $bill['bill_status_name'],
                        $GLOBALS['urgent'][$bill['is_urgent']],
                        $bill['payTypeName'],
                        $arrive_time,
                        $bill['createTime'],
                        $bill['goods_name_str'],
                        $bill['bill_totalAmount'],
                        $bill['bill_money'], //订单金额
                        $bill['bill_receivable_money'],  //应收金额
                        $bill['bill_received_money'],   //已收金额
                        $bill['deliver_city'],
                        $bill['deliver_county'],
                        $bill['distribution_name'],
                        $bill['distribution_technicia'],
                        $this->getDistribution_technician_mobile($bill['distribution_technician_id']),
                        $bill['deliver_mobile'],
                        $bill['deliver_name'],
                        $bill['creator'],
                        $bill['bill_withdraw_name']
                    )
                );

            }
        }

        echo json_encode($result_array);
    }
}